from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
import time
from selenium.webdriver import ActionChains


driver = webdriver.Chrome()

driver.get("https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx")

# 窗口最大化
driver.maximize_window()

# 输入账号
driver.find_element_by_id('email').send_keys('18937295575')

# 输入密码
driver.find_element_by_id('pwd').send_keys('gzy1314')

# 输入验证码
driver.find_element_by_id('code').send_keys(input('请输入:'))


# 点击登录
driver.find_element_by_id('denglu').click()

# 搜索春江花月夜
time.sleep(2)
sousuo = driver.find_element(By.ID,'txtKey')
sousuo.send_keys('春江花月夜')
sousuo.send_keys(Keys.ENTER)

# 向下滑动
time.sleep(2)
for a in range(1,4):
    driver.execute_script('window.scrollTo(0,500)')
    driver.get_screenshot_as_file("test%d.png" %(a))

# 点击收藏
time.sleep(2)
driver.find_element_by_id('likeImg5256').click()

# 点击我的页面
time.sleep(2)
driver.find_element_by_xpath('//*[@id="html"]/body/div[1]/div/div[2]/div[1]/a[6]').click()

# 点击收藏的春江花月夜
# time.sleep(2)
# driver.find_element_by_link_text('春江花月夜').click()

# 关闭网页
driver.quit()

